home *** CD-ROM | disk | FTP | other *** search
- package asp.netobjects.nfx.wizard;
-
- import asp.netobjects.nfx.ui.EtchedTopBorder;
- import asp.netobjects.nfx.util.ExceptionHandler;
- import asp.netobjects.nfx.util.ExternalError;
- import asp.netobjects.nfx.util.InternalError;
- import com.netobjects.nfc.api.NFXJDialog;
- import com.sun.java.swing.BorderFactory;
- import com.sun.java.swing.Box;
- import com.sun.java.swing.BoxLayout;
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JDialog;
- import com.sun.java.swing.JPanel;
- import java.awt.BorderLayout;
- import java.awt.CardLayout;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dialog;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Frame;
- import java.awt.Insets;
- import java.awt.Toolkit;
- import java.awt.Window;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowEvent;
- import java.util.EventObject;
-
- public class WizardView extends JDialog implements ActionListener {
- private Wizard dmWizard;
- private int dmWidth = 470;
- private int dmHeight = 318;
- private WizardButton dmBtnBack;
- private WizardButton dmBtnNext;
- private WizardButton dmBtnFinish;
- private WizardButton dmBtnCancel;
- private JPanel dmMainPanel;
- private JPanel dmButtonPanel;
- private JPanel dmPagePanel;
- private CardLayout dmPagePanelCardLayout;
-
- public WizardView(Wizard wizard, Frame parent, String title) {
- super(parent, title);
- this.dmWizard = wizard;
- this.dmWidth = 470;
- this.dmHeight = 318;
- this.createControls();
- }
-
- public WizardView(Wizard wizard, Frame parent, String title, int width, int height) {
- super(parent, title);
- this.dmWizard = wizard;
- this.dmWidth = width;
- this.dmHeight = height;
- this.createControls();
- }
-
- private void createControls() {
- ((Dialog)this).setResizable(true);
- if (this instanceof NFXJDialog) {
- ((Dialog)this).setModal(false);
- } else if (this instanceof JDialog) {
- ((Dialog)this).setModal(true);
- }
-
- ((Component)this).setSize(this.dmWidth, this.dmHeight);
- ((Component)this).setFont(new Font("Helvetica", 0, 12));
- this.dmMainPanel = new JPanel();
- this.dmMainPanel.setLayout(new BorderLayout());
- this.dmMainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- ((JDialog)this).getContentPane().add(this.dmMainPanel);
- WindowListener windowListener = new WindowListener(this);
- ((Window)this).addWindowListener(windowListener);
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- ((Component)this).setLocation(screenSize.width / 2 - 235, screenSize.height / 2 - 159);
- this.dmPagePanel = new JPanel();
- this.dmPagePanelCardLayout = new CardLayout();
- this.dmPagePanel.setLayout(this.dmPagePanelCardLayout);
- this.dmPagePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
- this.dmMainPanel.add(this.dmPagePanel, "Center");
- this.dmButtonPanel = new JPanel();
- this.dmButtonPanel.setLayout(new BoxLayout(this.dmButtonPanel, 0));
- this.dmButtonPanel.setBorder(new EtchedTopBorder(1));
- Insets insets = ((Container)this).getInsets();
- int w = this.dmWidth - (insets.left + insets.right) - 30 - 16 - 320;
- this.dmButtonPanel.add(Box.createRigidArea(new Dimension(w, 23)));
- this.dmBtnCancel = new WizardButton(this, "Cancel");
- this.dmBtnCancel.setMnemonic(this.dmBtnCancel.getText().charAt(0));
- this.dmBtnCancel.setEnabled(true);
- this.dmBtnCancel.addActionListener(this);
- this.dmButtonPanel.add(this.dmBtnCancel);
- this.dmButtonPanel.add(Box.createRigidArea(new Dimension(8, 23)));
- this.dmBtnBack = new WizardButton(this, "< Back");
- this.dmBtnBack.setMnemonic('B');
- this.dmBtnBack.setEnabled(false);
- this.dmBtnBack.addActionListener(this);
- this.dmButtonPanel.add(this.dmBtnBack);
- this.dmBtnNext = new WizardButton(this, "Next >");
- this.dmBtnNext.setMnemonic(this.dmBtnNext.getText().charAt(0));
- this.dmBtnNext.setEnabled(false);
- this.dmBtnNext.addActionListener(this);
- this.dmButtonPanel.add(this.dmBtnNext);
- this.dmButtonPanel.add(Box.createRigidArea(new Dimension(8, 23)));
- this.dmBtnFinish = new WizardButton(this, "Finish");
- this.dmBtnFinish.setMnemonic(this.dmBtnFinish.getText().charAt(0));
- this.dmBtnFinish.setEnabled(false);
- this.dmBtnFinish.addActionListener(this);
- this.dmButtonPanel.add(this.dmBtnFinish);
- this.dmMainPanel.add("South", this.dmButtonPanel);
- }
-
- public ExceptionHandler getExceptionHandler() {
- return this.dmWizard.getExceptionHandler();
- }
-
- public CardLayout getCardLayout() {
- return this.dmPagePanelCardLayout;
- }
-
- public JButton getBackButton() {
- return this.dmBtnBack;
- }
-
- public JButton getNextButton() {
- return this.dmBtnNext;
- }
-
- public JButton getFinishButton() {
- return this.dmBtnFinish;
- }
-
- public JButton getCancelButton() {
- return this.dmBtnCancel;
- }
-
- public void initialize() throws InternalError, ExternalError {
- this.dmPagePanelCardLayout.first(this.dmPagePanel);
- }
-
- public void addPageView(String id, WizardPageView view) {
- this.dmPagePanel.add(id, view);
- }
-
- public void removePageView(WizardPageView view) {
- this.dmPagePanelCardLayout.removeLayoutComponent(view);
- }
-
- public void showPageView(String id) {
- this.dmPagePanelCardLayout.show(this.dmPagePanel, id);
- }
-
- public void enableNext(boolean enable) {
- this.dmBtnNext.setEnabled(enable);
- }
-
- public void enablePrevious(boolean enable) {
- this.dmBtnBack.setEnabled(enable);
- }
-
- public void enableFinish(boolean enable) {
- this.dmBtnFinish.setEnabled(enable);
- }
-
- public void windowClosing(WindowEvent event) {
- this.dmWizard.setOk(false);
- this.dmWizard.destroy();
- ((Window)this).dispose();
- }
-
- public void actionPerformed(ActionEvent event) {
- try {
- Object object = ((EventObject)event).getSource();
- String file = null;
- if (object == this.dmBtnBack) {
- this.dmWizard.previousPage();
- } else if (object == this.dmBtnNext) {
- this.dmWizard.nextPage();
- } else {
- if (object == this.dmBtnFinish) {
- this.dmWizard.finish();
- this.dmWizard.setOk(true);
- this.dmWizard.destroy();
- ((Window)this).dispose();
- return;
- }
-
- if (object == this.dmBtnCancel) {
- this.dmWizard.setOk(false);
- this.dmWizard.destroy();
- ((Window)this).dispose();
- return;
- }
- }
- } catch (Throwable t) {
- if (this.dmWizard.getExceptionHandler() != null) {
- this.dmWizard.getExceptionHandler().handleException(t);
- return;
- }
-
- t.printStackTrace();
- }
-
- }
- }
-